<template>
  <div class="health-test-date-root">
    <el-table :data="tableData"
    height="500"
    v-loading.body="loading"
    element-loading-text="新联为您加载数据中"
    border
    >
      <el-table-column
              prop="time"
              label="检测时间"
              sortable
              >
      </el-table-column>
      <el-table-column
              prop="serialNum"
              label="设备序号"
              sortable
              >
      </el-table-column>
      <el-table-column
              prop="glycemic"
              label="血糖值"
              sortable
              :formatter="glycemicFormatter"
              >
      </el-table-column>
      <el-table-column
              prop="uid"
              label="测试类型"
              >
              <template scope="scope">
              <el-select v-model="scope.row.timeType">
                <el-option
                  v-for="item in timeTypeOption"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
export default{
  name: 'healthTestData',
  data () {
    return {
      loading: true,
      tableData: [],
      timeTypeOption: [
        {
          value: 0,
          label: '凌晨'
        },
        {
          value: 1,
          label: '早餐前'
        },
        {
          value: 2,
          label: '早晨后'
        },
        {
          value: 3,
          label: '午餐前'
        },
        {
          value: 4,
          label: '午餐后'
        },
        {
          value: 5,
          label: '晚餐前'
        },
        {
          value: 6,
          label: '晚餐后'
        },
        {
          value: 7,
          label: '睡前'
        }]
    }
  },
  methods: {
    fetchData () {
      this.$http({
        method: 'POST',
        url: 'http://api.xltest.cn/sryk/test-data',
        data: {
          'uid': 12
        }
      }).then(data => {
        // var res = JSON.parse(data.body)
        var res = data.body
        console.log(res)
        this.tableData = res.testData
        this.loading = false
      })
    },
    glycemicFormatter (row, column) {
      return row.glycemic + 'mmol/L'
    }
  },
  created () {
    this.fetchData()
  },
  beforeRouteEnter: (to, from, next) => {
    next(vm => {
      console.log(to.query.uid)
    })
  }
}
</script>